import pandas as pd
from milvus_support import MilvusBase as milvus_support
from sentence_transformers import SentenceTransformer

model = SentenceTransformer('/model/data/transformers/BAAI/bge-large-zh-v1.5')
config = {"milvus_host": "70.182.56.3", "milvus_port": 19530, "VECTOR_DIM": 1024, "METRIC_TYPE":"COSINE"}
milvus_cli = milvus_support(**config)


def add_qa():
    df = pd.read_excel(r"/model/Z00013232/小智语料库向量数据库语料.xlsx", header=None)
    q_list = []
    a_list = []
    data_list = df.values.tolist()
    for data in data_list:
        q_list.append(data[0])
        a_list.append(data[1])
    milvus_cli.create_question_collection("support_qa")
    for i in range(len(q_list)):
        embeddings_1 = model.encode(q_list[i], normalize_embeddings=True)
        milvus_cli.insert_question("support_qa", embeddings_1, q_list[i], a_list[i])





def add_text():
    milvus_cli.create_text_collection("support_text")
    with open('V6_data.txt', 'r', encoding='utf-8') as file:
        # 循环遍历文件的每一行
        index = 0
        for line in file:
            # 处理每一行的内容
            if line.strip():  # 如果行不是空的，则执行下面的代码
                embeddings_1 = model.encode(line, normalize_embeddings=True)
                milvus_cli.insert_text("support_text", embeddings_1, line)
                print(index)
                index += 1

if __name__ == '__main__':
    add_text()
    # add_qa()
